package uplb.ics.cs190.e2d.core;

import uplb.ics.cs190.e2d.display.FullScreenMode;
import uplb.ics.cs190.e2d.display.OpenGLMode;
import uplb.ics.cs190.e2d.display.WindowedMode;
import uplb.ics.cs190.e2d.io.StandardIO;
import uplb.ics.cs190.e2d.time.OpenGLTimer;
import uplb.ics.cs190.e2d.time.StandardTimer;

public class PCLoader implements Console {

	protected Game game;
	protected Engine engine;
	
	public PCLoader() {
		engine = Engine.getInstance();
	}
	
	@Override
	public void setup(Game game) {
		try {
			/*if(!GSystem.isVersionValid("1.6.0")) {
				System.exit(-1);
			}*/

			engine.mountGame(game);

			engine.fileIO = new StandardIO(game.getClass());
			
			if(game.isOpenGL()) {
				engine.display = new OpenGLMode(
						game.getSize(), 
						game.getTitle(),
						game.isFullScreen(),
						game.useVsync());
				engine.timer = new OpenGLTimer();
			} else {
				engine.timer = new StandardTimer();
				if(game.isFullScreen()) {
					try {
						engine.display = new FullScreenMode(game.getSize(), 
								game.getTitle(),
								game.useBufferStrategy());
					} catch(RuntimeException e) {
						engine.display = new WindowedMode(game.getSize(), 
								game.getTitle(),
								game.useBufferStrategy());
					}
				} else {
					engine.display = new WindowedMode(game.getSize(), 
							game.getTitle(),
							game.useBufferStrategy());
				}
			}
		} catch(Exception e) {
			System.exit(-1);
		}
	}

	@Override
	public Game getGame() {
		return this.game;
	}

	@Override
	public void start() {
		engine.start();
	}

	@Override
	public void stop() {
		// TODO Auto-generated method stub
		
	}
}
